package com.example.ivos.dictoption.controller;

import com.example.ivos.base.response.JsonResult;
import com.example.ivos.dictoption.pojo.dto.DictOptionParam;
import com.example.ivos.dictoption.pojo.dto.DictOptionQuery;
import com.example.ivos.dictoption.pojo.entity.DictOption;
import com.example.ivos.dictoption.pojo.vo.DictOptionVO;
import com.example.ivos.dictoption.service.DictOptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "字典项管理模块")
@RestController
@Slf4j
@RequestMapping("/v1/dictOption/")
public class DictOptionController {
    @Autowired
    private DictOptionService dictOptionService;

    @ApiOperation("字典项列表")
    @GetMapping("select")
    public JsonResult select(DictOptionQuery dictOptionQuery){
        log.debug("查询字典项列表dictOptionQuery:{}", dictOptionQuery);
        List<DictOptionVO> dictOptionVOList = dictOptionService.select(dictOptionQuery);
        return JsonResult.ok(dictOptionVOList);
    }

    @ApiOperation("字典项管理")
    @PostMapping("save")
    public JsonResult save(DictOptionParam dictOptionParam){
        log.debug("保存字典项信息dictOptionParam:{}", dictOptionParam);
        dictOptionService.save(dictOptionParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除字典项")
    @PostMapping("delete")
    public JsonResult delete(Long id){
        log.debug("删除字典项信息id:{}", id);
        dictOptionService.delete(id);
        return JsonResult.ok();
    }


    @ApiOperation("根据字典code查询字典项")
    @GetMapping("selectOptions")
    public JsonResult selectByCode(String code){
        log.debug("根据code查询字典项信息code:{}", code);
        List<DictOptionVO> list= dictOptionService.selectByCode(code);
        return JsonResult.ok(list);
    }

}
